package com.ai5suoai.ams.entity;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.Method;

/**
 * @author chenzhenjia
 * @since 16/3/31
 */
public abstract class AbstractToVo<E, T> implements IToVo<E> {

    @Override
    public E toVo() {
        try {
            Method toVo = this.getClass().getMethod("toVo");
            Class<?> returnType = toVo.getReturnType();
            E e = (E) returnType.newInstance();
            BeanUtils.copyProperties(getThis(), e);
            System.out.println("returnType = " + returnType);
            return e;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public abstract T getThis();
}
